home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / win / tkWinPixmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  4.2 KB  |  185 lines  |  [TEXT/CWIE]

  1. /* 
  2.  * tkWinPixmap.c --
  3.  *
  4.  *    This file contains the Xlib emulation functions pertaining to
  5.  *    creating and destroying pixmaps.
  6.  *
  7.  * Copyright (c) 1995 Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  *
  12.  * SCCS: @(#) tkWinPixmap.c 1.18 97/08/06 15:36:23
  13.  */
  14.  
  15. #include "tkWinInt.h"
  16.  
  17.  
  18. /*
  19.  *----------------------------------------------------------------------
  20.  *
  21.  * Tk_GetPixmap --
  22.  *
  23.  *    Creates an in memory drawing surface.
  24.  *
  25.  * Results:
  26.  *    Returns a handle to a new pixmap.
  27.  *
  28.  * Side effects:
  29.  *    Allocates a new Win32 bitmap.
  30.  *
  31.  *----------------------------------------------------------------------
  32.  */
  33.  
  34. Pixmap
  35. Tk_GetPixmap(display, d, width, height, depth)
  36.     Display* display;
  37.     Drawable d;
  38.     int width;
  39.     int height;
  40.     int depth;
  41. {
  42.     TkWinDrawable *newTwdPtr, *twdPtr;
  43.     int planes;
  44.     Screen *screen;
  45.     
  46.     display->request++;
  47.  
  48.     newTwdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable));
  49.     newTwdPtr->type = TWD_BITMAP;
  50.     newTwdPtr->bitmap.depth = depth;
  51.     twdPtr = (TkWinDrawable *)d;
  52.     if (twdPtr->type != TWD_BITMAP) {
  53.     if (twdPtr->window.winPtr == NULL) {
  54.         newTwdPtr->bitmap.colormap = DefaultColormap(display,
  55.             DefaultScreen(display));
  56.     } else {
  57.         newTwdPtr->bitmap.colormap = twdPtr->window.winPtr->atts.colormap;
  58.     }
  59.     } else {
  60.     newTwdPtr->bitmap.colormap = twdPtr->bitmap.colormap;
  61.     }
  62.     screen = &display->screens[0];
  63.     planes = 1;
  64.     if (depth == screen->root_depth) {
  65.     planes = (int) screen->ext_data;
  66.     depth /= planes;
  67.     }
  68.     newTwdPtr->bitmap.handle = CreateBitmap(width, height, planes, depth, NULL);
  69.  
  70.     if (newTwdPtr->bitmap.handle == NULL) {
  71.     ckfree((char *) newTwdPtr);
  72.     return None;
  73.     }
  74.     
  75.     return (Pixmap)newTwdPtr;
  76. }
  77.  
  78. /*
  79.  *----------------------------------------------------------------------
  80.  *
  81.  * Tk_FreePixmap --
  82.  *
  83.  *    Release the resources associated with a pixmap.
  84.  *
  85.  * Results:
  86.  *    None.
  87.  *
  88.  * Side effects:
  89.  *    Deletes the bitmap created by Tk_GetPixmap.
  90.  *
  91.  *----------------------------------------------------------------------
  92.  */
  93.  
  94. void
  95. Tk_FreePixmap(display, pixmap)
  96.     Display* display;
  97.     Pixmap pixmap;
  98. {
  99.     TkWinDrawable *twdPtr = (TkWinDrawable *) pixmap;
  100.  
  101.     display->request++;
  102.     if (twdPtr != NULL) {
  103.     DeleteObject(twdPtr->bitmap.handle);
  104.     ckfree((char *)twdPtr);
  105.     }
  106. }
  107.  
  108. /*
  109.  *----------------------------------------------------------------------
  110.  *
  111.  * TkSetPixmapColormap --
  112.  *
  113.  *    The following function is a hack used by the photo widget to
  114.  *    explicitly set the colormap slot of a Pixmap.
  115.  *
  116.  * Results:
  117.  *    None.
  118.  *
  119.  * Side effects:
  120.  *    None.
  121.  *
  122.  *----------------------------------------------------------------------
  123.  */
  124.  
  125. void
  126. TkSetPixmapColormap(pixmap, colormap)
  127.     Pixmap pixmap;
  128.     Colormap colormap;
  129. {
  130.     TkWinDrawable *twdPtr = (TkWinDrawable *)pixmap;
  131.     twdPtr->bitmap.colormap = colormap;
  132. }
  133.  
  134. /*
  135.  *----------------------------------------------------------------------
  136.  *
  137.  * XGetGeometry --
  138.  *
  139.  *    Retrieve the geometry of the given drawable.  Note that
  140.  *    this is a degenerate implementation that only returns the
  141.  *    size of a pixmap.
  142.  *
  143.  * Results:
  144.  *    Returns 0.
  145.  *
  146.  * Side effects:
  147.  *    None.
  148.  *
  149.  *----------------------------------------------------------------------
  150.  */
  151.  
  152. int
  153. XGetGeometry(display, d, root_return, x_return, y_return, width_return,
  154.     height_return, border_width_return, depth_return)
  155.     Display* display;
  156.     Drawable d;
  157.     Window* root_return;
  158.     int* x_return;
  159.     int* y_return;
  160.     unsigned int* width_return;
  161.     unsigned int* height_return;
  162.     unsigned int* border_width_return;
  163.     unsigned int* depth_return;
  164. {
  165.     TkWinDrawable *twdPtr = (TkWinDrawable *)d;
  166.     HDC dc;
  167.     BITMAPINFO info;
  168.  
  169.     if ((twdPtr->type != TWD_BITMAP) || (twdPtr->bitmap.handle == NULL)) {
  170.     panic("XGetGeometry: invalid pixmap");
  171.     }
  172.     dc = GetDC(NULL);
  173.     info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  174.     info.bmiHeader.biBitCount = 0;
  175.     if (!GetDIBits(dc, twdPtr->bitmap.handle, 0, 0, NULL, &info,
  176.         DIB_RGB_COLORS)) {
  177.     panic("XGetGeometry: unable to get bitmap size");
  178.     }
  179.     ReleaseDC(NULL, dc);
  180.  
  181.     *width_return = info.bmiHeader.biWidth;
  182.     *height_return = info.bmiHeader.biHeight;
  183.     return 1;
  184. }
  185.